﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Jay.Sc2.Bof.Lib;

namespace Jay.Sc2.Bof.Windows
{
	public partial class RaceSelectorForm : Form
	{
		private int m_SpaceX = 3;
		private int m_SpaceY = 1;
		private Brush m_StringBrush;
		private Brush m_StringSelectedBrush;
		private Brush m_BackgroundBrush;
		private Brush m_BackgroundSelectedBrush;
		private GenerationForm m_GenerationForm;

		public RaceSelectorForm()
		{
			InitializeComponent();
			cbRace.Items.Add("Terran");
			cbRace.Items.Add("Protoss");
			cbRace.Items.Add("Zerg");
			cbRace.DrawMode = DrawMode.OwnerDrawVariable;
			cbRace.ItemHeight = ilCombo.ImageSize.Height;
			cbRace.DrawItem += new DrawItemEventHandler(cbRace_DrawItem);
			m_StringBrush = new SolidBrush(cbRace.ForeColor);
			m_BackgroundBrush = new SolidBrush(cbRace.BackColor);
			m_BackgroundSelectedBrush = new SolidBrush(SystemColors.Highlight);
			m_StringSelectedBrush = new SolidBrush(SystemColors.HighlightText);
			cbRace.SelectedIndex = 0;
		}

		void cbRace_DrawItem(object sender, DrawItemEventArgs e)
		{
			if (e.Index != -1)
			{
				bool selected = e.State.HasFlag(DrawItemState.Selected);
				e.Graphics.FillRectangle(selected ? m_BackgroundSelectedBrush : m_BackgroundBrush, e.Bounds);
				e.Graphics.DrawImage(ilCombo.Images[e.Index], e.Bounds.Left, e.Bounds.Top);
				e.Graphics.DrawString(cbRace.Items[e.Index].ToString(), cbRace.Font,selected ? m_StringSelectedBrush : m_StringBrush, ilCombo.ImageSize.Width + m_SpaceX, e.Bounds.Top + m_SpaceY);
			}
		}

		private void bOk_Click(object sender, EventArgs e)
		{
			switch (cbRace.SelectedItem.ToString())
			{
				case "Terran":
					Program.CurrentRace = TerranRace.Instance;
					break;
				case "Protoss":
					Program.CurrentRace = ProtossRace.Instance;
					break;
				case "Zerg":
					Program.CurrentRace = ZergRace.Instance;
					break;
			}
			Hide();
			m_GenerationForm = new GenerationForm(this);
			m_GenerationForm.Show();
		}

		private void cbRace_SelectedIndexChanged(object sender, EventArgs e)
		{
		}
	}
}
